package com.zx.mes.senior.swap;

import com.sun.org.apache.xpath.internal.operations.Mod;
import org.junit.Test;

import java.lang.reflect.Modifier;

/**
 * 数字交换
 * @author huayunlong
 * @date 2018-7-23
 */
public class Swap {

    @Test
    public void test(){
        int a = 4;
        int b = 6;
        int temp;
        temp = b;
        b = a;
        a = temp;
        System.out.println("a:"+a+"  "+"b:"+b);

    }

    @Test
    public void test2(){
        int a = 4;
        int b = 6;
        a = a + b;
        b = a - b;
        a = a - b;
        /// 加完之后可能会出现值超过 int范围
        System.out.println("a:"+a+"  "+"b:"+b);
    }

    @Test
    public void test3(){
        int a = 4;
        int b = 6;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println("a:"+a+"  "+"b:"+b);
    }

    /**
     * 按位与 优化有很多判断的情况
     */
    @Test
    public void test4(){
        int PUBLIC = 0x1;
        System.out.println(PUBLIC & 3);
        System.out.println(PUBLIC & 1);
        System.out.println(PUBLIC & 2);
    }

    @Test
    public void test5(){
        Class clazz = User.class;
        int modifiers = clazz.getModifiers();

        // 判断是否是abstract修饰符
        System.out.println(Modifier.isAbstract(modifiers));
        // 判断是否是接口
        System.out.println(Modifier.isInterface(modifiers));

        System.out.println(Modifier.isPublic(modifiers));
        // 获取其修饰符
        System.out.println(clazz.getModifiers());
    }

    /**
     * 进制转换
     */
    @Test
    public void test6(){
        int ten = 43;
        System.out.println(Integer.toBinaryString(43));
        System.out.println(Integer.toHexString(ten));
        System.out.println(Integer.toOctalString(ten));
    }
}
